package mapViewer.screens;

import context.*;

import mapViewer.MapLoader;

import simpleMapService.Location;
import simpleMapService.PixelPoint;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;


// ******************************************************************
// *** INNER CLASS: ShowDetailsPanel
// ******************************************************************
public class ShowDetailsPanel extends Form implements Debug.Constants
{ //private static final boolean DEBUG=true; // Overriding Debug.Constants.DEBUG
  private final static Command okCommand=new Command("OK",Command.OK,1);
  private static final Command exitCommand=new Command("Exit",Command.EXIT,1);

  private StringItem latitude=new StringItem("Latitude:","UNKNOWN");
  private StringItem longitude=new StringItem("Longitude:","UNKNOWN");
  private StringItem scale=new StringItem("Scale:","UNKNOWN");
  private StringItem north=new StringItem("North:","UNKNOWN");
  private StringItem south=new StringItem("South:","UNKNOWN");
  private StringItem east=new StringItem("East:","UNKNOWN");
  private StringItem west=new StringItem("West:","UNKNOWN");

  // ****************************************************************
  // *** CONSTRUCTOR: ShowDetailsPanel
  // ****************************************************************
  public ShowDetailsPanel(String title)
  { super(title);
    append(latitude);
    append(longitude);
    append(scale);
    append(north);
    append(south);
    append(east);
    append(west);
    //availableMapSheets=getAvailableMapSheets();
    //append(availableMapSheets);
  }  

// ******************************************************************
// *** METHOD: show
// ******************************************************************
  public void show(MapLoader mapLoader)
  { Location mapCenter=mapLoader.getMapCenter();
    Location northWest=mapLoader.getLocation(new PixelPoint(0,0));
    int w=mapLoader.getImageWidth();
    int h=mapLoader.getImageHeight();
    Location southEast=mapLoader.getLocation(new PixelPoint(w,h));
    this.latitude.setText(""+mapCenter.getLatitude());
    this.longitude.setText(""+mapCenter.getLongitude());
    this.scale.setText(""+mapLoader.getScale());
    this.north.setText(""+northWest.getLatitude());
    this.south.setText(""+southEast.getLatitude());
    this.west.setText(""+northWest.getLongitude());
    this.east.setText(""+southEast.getLongitude());
    final Displayable prev=Context.setCurrent(this);
    addCommand(exitCommand);
    addCommand(okCommand);
    setCommandListener(new CommandListener()
    { public void commandAction(Command c, Displayable s)
      { if(c==exitCommand) Context.exit();
        else if(c==okCommand)
        {
          //int n=availableMapSheets.getSelectedIndex();
          //mapLoader=((MapSheet)mapSheetSet.elementAt(n)).mapLoader;
          //startLoadMapThread();
          Context.setCurrent(prev);
        }
      }
    });
  }
}
